package io.esirong.network.retrofit;

import java.io.File;
import java.util.List;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;


/**
 *
 */
public class Utils {
    public static final String MULTIPART_FORM_DATA = "multipart/form-data";

    /**
     * @param file 文件
     * @return RequestBody
     */
    public static RequestBody createFile(File file) {
        return RequestBody.create(MediaType.parse(MULTIPART_FORM_DATA + "; charset=utf-8"), file);
    }

    /**
     * @param files 文件s
     * @return RequestBody
     */
    public static RequestBody createFile(List<File> files) {
        // MultipartBody.Part  和后端约定好Key，这里的partName是用file
        MultipartBody.Builder builder = new MultipartBody.Builder();

        for (File file : files) {
            builder.addPart(createFile(file));
        }
        return builder.build();
    }

}
